package art_of_java_concurrent_programming.executor;

import java.util.concurrent.*;

/**
 * @author lixiangke
 * @date 2018/3/6
 */
public class ThreadPoolExecutorTest {
    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                2,
                3,
                60,
                TimeUnit.SECONDS,
                // new LinkedBlockingQueue<Runnable>(),
                new SynchronousQueue<Runnable>(),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());

                // ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(
                // 2,
                // Executors.defaultThreadFactory());

        executor.execute(new ThreadPoolTask());
        executor.execute(new ThreadPoolTask());
        executor.execute(new ThreadPoolTask());
        executor.execute(new ThreadPoolTask());
        executor.shutdown();
    }

    static class ThreadPoolTask implements Runnable {
        @Override
        public void run() {
            System.out.println("Task Run...");
        }
    }
}
